aboutsummaryrefslogtreecommitdiff
path: root/src/pages/blog/[...slug].astro
blob: d12ff055a404ff3d30b54d5d7ea613ccb569c1ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
import { type CollectionEntry, getCollection } from "astro:content";
import Comments from "../../components/Comments.astro";
import Layout from "../../layouts/BaseLayout.astro";
import blogPostSchema from "../../utils/schemas/blogPostSchema";
import dayjs from "dayjs";

type Props = CollectionEntry<"blog">;

export async function getStaticPaths() {
	const posts = await getCollection("blog", ({ data }) => {
		return data.draft !== true;
	});

	return posts.map((post) => ({
		params: { slug: post.slug },
		props: post,
	}));
}

const post = Astro.props;

const { Content, remarkPluginFrontmatter } = await post.render();

const description = post.data.description;
const isBasedOn = post.data.basedOn;
const lang = post.data.lang;
const preview = `/images/preview/${post.slug}.png`;
const slug = post.slug;
const title = post.data.title;

const dateModified = post.data.dateModified?.toISOString();
const datePublished = post.data.datePublished.toISOString();
const formattedDate = dayjs(post.data.datePublished.toString()).format("MMMM DD, YYYY");

const schema = blogPostSchema({
	siteUrl: new URL("/", Astro.site).toString(),
	dateModified,
	datePublished,
	description,
	isBasedOn,
	lang,
	preview,
	slug,
	title,
});
---

<style lang="scss">
	@use "../../scss/variables" as *;

	p {
		opacity: 0.5;
	}
</style>

<Layout title={title} description={description} preview={preview} lang={lang} schema={schema}>
	<article>
		<header>
			<h1>{title}</h1>

			<p>
				<small>
					Posted
					<time datetime={datePublished} lang="en">{formattedDate}</time>
					<span>&nbsp;•&nbsp;</span>
					<span>{remarkPluginFrontmatter.minutesRead}</span>
				</small>
			</p>
		</header>

		<section>
			<Content />
		</section>

		<section>
			<Comments />
		</section>
	</article>
</Layout>